<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生信息管理系统</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            line-height: 1.6;
            color: #333;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        h1, h2 {
            color: #2c3e50;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }
        .tabs {
            display: flex;
            margin: 20px 0;
            border-bottom: 1px solid #ddd;
        }
        .tab {
            padding: 10px 20px;
            cursor: pointer;
            background: #f5f5f5;
            border: 1px solid #ddd;
            border-bottom: none;
            margin-right: 5px;
            border-radius: 5px 5px 0 0;
        }
        .tab.active {
            background: white;
            border-color: #3498db;
            color: #3498db;
            font-weight: bold;
        }
        .tab-content {
            display: none;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 0 5px 5px 5px;
            margin-bottom: 30px;
        }
        .tab-content.active {
            display: block;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: inline-block;
            width: 120px;
            vertical-align: top;
        }
        input, select, textarea {
            width: 300px;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
        }
        button:hover {
            background: #2980b9;
        }
        .response {
            margin-top: 20px;
            padding: 15px;
            border-radius: 4px;
            background: #f8f9fa;
            white-space: pre-wrap;
            font-family: monospace;
        }
        .success {
            border: 1px solid #2ecc71;
        }
        .error {
            border: 1px solid #e74c3c;
        }
        .grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
        }
        @media (max-width: 768px) {
            .grid {
                grid-template-columns: 1fr;
            }
            input, select, textarea {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>学生信息管理系统</h1>

        <div class="tabs">
            <div class="tab active" data-tab="basic">基本信息管理</div>
            <div class="tab" data-tab="score">考核成绩管理</div>
            <div class="tab" data-tab="attendance">考勤记录管理</div>
            <div class="tab" data-tab="employment">就业信息管理</div>
        </div>

        <!-- 学生基本信息管理 -->
        <div id="basic" class="tab-content active">
            <h2>学生基本信息管理</h2>

            <div class="grid">
                <div>
                    <h3>新增学生</h3>
                    <form id="createBasicForm">
                        <div class="form-group">
                            <label>学生班级:</label>
                            <input type="text" name="学生班级" required>
                        </div>
                        <div class="form-group">
                            <label>学生姓名:</label>
                            <input type="text" name="学生姓名" required>
                        </div>
                        <div class="form-group">
                            <label>籍贯:</label>
                            <input type="text" name="籍贯">
                        </div>
                        <div class="form-group">
                            <label>毕业院校:</label>
                            <input type="text" name="毕业院校">
                        </div>
                        <div class="form-group">
                            <label>专业:</label>
                            <input type="text" name="专业">
                        </div>
                        <div class="form-group">
                            <label>入学时间:</label>
                            <input type="date" name="入学时间">
                        </div>
                        <div class="form-group">
                            <label>毕业时间:</label>
                            <input type="date" name="毕业时间">
                        </div>
                        <div class="form-group">
                            <label>学历:</label>
                            <input type="text" name="学历">
                        </div>
                        <div class="form-group">
                            <label>顾问编号:</label>
                            <input type="text" name="顾问编号">
                        </div>
                        <div class="form-group">
                            <label>年龄:</label>
                            <input type="number" name="年龄">
                        </div>
                        <div class="form-group">
                            <label>性别:</label>
                            <select name="性别" required>
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                        </div>
                        <button type="submit">新增</button>
                    </form>
                </div>

                <div>
                    <h3>查询/更新/删除学生</h3>
                    <form id="getBasicForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="student_id" required>
                        </div>
                        <button type="submit" formaction="query">查询</button>
                    </form>

                    <form id="updateBasicForm" style="margin-top: 20px;">
                        <input type="hidden" name="student_id">
                        <div class="form-group">
                            <label>学生班级:</label>
                            <input type="text" name="学生班级">
                        </div>
                        <div class="form-group">
                            <label>籍贯:</label>
                            <input type="text" name="籍贯">
                        </div>
                        <div class="form-group">
                            <label>毕业院校:</label>
                            <input type="text" name="毕业院校">
                        </div>
                        <div class="form-group">
                            <label>专业:</label>
                            <input type="text" name="专业">
                        </div>
                        <div class="form-group">
                            <label>毕业时间:</label>
                            <input type="date" name="毕业时间">
                        </div>
                        <div class="form-group">
                            <label>学历:</label>
                            <input type="text" name="学历">
                        </div>
                        <div class="form-group">
                            <label>顾问编号:</label>
                            <input type="text" name="顾问编号">
                        </div>
                        <div class="form-group">
                            <label>年龄:</label>
                            <input type="number" name="年龄">
                        </div>
                        <div class="form-group">
                            <label>性别:</label>
                            <select name="性别">
                                <option value="">-- 不修改 --</option>
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                        </div>
                        <button type="submit">更新</button>
                        <button type="button" id="deleteBasicBtn">删除</button>
                    </form>
                </div>
            </div>

            <div class="form-group">
                <h3>查询所有学生</h3>
                <form id="getAllBasicForm">
                    <div class="form-group">
                        <label>跳过条数:</label>
                        <input type="number" name="skip" value="0">
                    </div>
                    <div class="form-group">
                        <label>查询条数:</label>
                        <input type="number" name="limit" value="10">
                    </div>
                    <button type="submit">查询</button>
                </form>
            </div>

            <div class="response" id="basicResponse"></div>
        </div>

        <!-- 学生考核成绩管理 -->
        <div id="score" class="tab-content">
            <h2>学生考核成绩管理</h2>

            <div class="grid">
                <div>
                    <h3>新增考核成绩</h3>
                    <form id="createScoreForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="学生编号" required>
                        </div>
                        <div class="form-group">
                            <label>考核序次:</label>
                            <input type="text" name="考核序次" required>
                        </div>
                        <div class="form-group">
                            <label>分数:</label>
                            <input type="number" step="0.01" name="分数" required>
                        </div>
                        <button type="submit">新增</button>
                    </form>
                </div>

                <div>
                    <h3>查询学生成绩</h3>
                    <form id="getScoreForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="student_id" required>
                        </div>
                        <button type="submit">查询</button>
                    </form>
                </div>
            </div>

            <div class="form-group">
                <h3>查询所有成绩</h3>
                <form id="getAllScoreForm">
                    <div class="form-group">
                        <label>跳过条数:</label>
                        <input type="number" name="skip" value="0">
                    </div>
                    <div class="form-group">
                        <label>查询条数:</label>
                        <input type="number" name="limit" value="100">
                    </div>
                    <button type="submit">查询</button>
                </form>
            </div>

            <div class="response" id="scoreResponse"></div>
        </div>

        <!-- 学生考勤记录管理 -->
        <div id="attendance" class="tab-content">
            <h2>学生考勤记录管理</h2>

            <div class="grid">
                <div>
                    <h3>新增考勤记录</h3>
                    <form id="createAttendanceForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="学生编号" required>
                        </div>
                        <div class="form-group">
                            <label>考核时间:</label>
                            <input type="datetime-local" name="考核时间">
                        </div>
                        <div class="form-group">
                            <label>补录标记:</label>
                            <select name="补录标记" required>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                        <button type="submit">新增</button>
                    </form>
                </div>

                <div>
                    <h3>查询学生考勤</h3>
                    <form id="getAttendanceForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="student_id" required>
                        </div>
                        <button type="submit">查询</button>
                    </form>
                </div>
            </div>

            <div class="form-group">
                <h3>查询所有考勤</h3>
                <form id="getAllAttendanceForm">
                    <div class="form-group">
                        <label>跳过条数:</label>
                        <input type="number" name="skip" value="0">
                    </div>
                    <div class="form-group">
                        <label>查询条数:</label>
                        <input type="number" name="limit" value="100">
                    </div>
                    <button type="submit">查询</button>
                </form>
            </div>

            <div class="response" id="attendanceResponse"></div>
        </div>

        <!-- 学生就业信息管理 -->
        <div id="employment" class="tab-content">
            <h2>学生就业信息管理</h2>

            <div class="grid">
                <div>
                    <h3>新增就业信息</h3>
                    <form id="createEmploymentForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="学生编号" required>
                        </div>
                        <div class="form-group">
                            <label>就业开放时间:</label>
                            <input type="date" name="就业开放时间">
                        </div>
                        <div class="form-group">
                            <label>OFFER下发时间:</label>
                            <input type="datetime-local" name="OFFER下发时间">
                        </div>
                        <div class="form-group">
                            <label>就业公司名称:</label>
                            <input type="text" name="就业公司名称" required>
                        </div>
                        <div class="form-group">
                            <label>就业薪资:</label>
                            <input type="number" step="0.01" name="就业薪资" required>
                        </div>
                        <button type="submit">新增</button>
                    </form>
                </div>

                <div>
                    <h3>查询/更新/删除就业信息</h3>
                    <form id="getEmploymentForm">
                        <div class="form-group">
                            <label>学生编号:</label>
                            <input type="number" name="student_id" required>
                        </div>
                        <button type="submit" formaction="query">查询</button>
                    </form>

                    <form id="updateEmploymentForm" style="margin-top: 20px;">
                        <input type="hidden" name="student_id">
                        <div class="form-group">
                            <label>就业开放时间:</label>
                            <input type="date" name="就业开放时间">
                        </div>
                        <div class="form-group">
                            <label>OFFER下发时间:</label>
                            <input type="datetime-local" name="OFFER下发时间">
                        </div>
                        <div class="form-group">
                            <label>就业公司名称:</label>
                            <input type="text" name="就业公司名称">
                        </div>
                        <div class="form-group">
                            <label>就业薪资:</label>
                            <input type="number" step="0.01" name="就业薪资">
                        </div>
                        <button type="submit">更新</button>
                        <button type="button" id="deleteEmploymentBtn">删除</button>
                    </form>
                </div>
            </div>

            <div class="form-group">
                <h3>查询所有就业信息</h3>
                <form id="getAllEmploymentForm">
                    <div class="form-group">
                        <label>跳过条数:</label>
                        <input type="number" name="skip" value="0">
                    </div>
                    <div class="form-group">
                        <label>查询条数:</label>
                        <input type="number" name="limit" value="100">
                    </div>
                    <button type="submit">查询</button>
                </form>
            </div>

            <div class="response" id="employmentResponse"></div>
        </div>
    </div>

    <script>
        // 切换标签页
        document.querySelectorAll('.tab').forEach(tab => {
            tab.addEventListener('click', () => {
                // 移除所有活跃状态
                document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
                document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));

                // 添加当前活跃状态
                tab.classList.add('active');
                const tabId = tab.getAttribute('data-tab');
                document.getElementById(tabId).classList.add('active');
            });
        });

        // API基础URL
        const API_BASE_URL = 'http://localhost:8011';

        // 工具函数：将表单数据转换为JSON
        function formToJson(form) {
            const formData = new FormData(form);
            const jsonData = {};
            formData.forEach((value, key) => {
                if (value !== '') jsonData[key] = value;
            });
            return jsonData;
        }

        // 工具函数：显示响应结果
        function showResponse(elementId, data, isError = false) {
            const responseElement = document.getElementById(elementId);
            responseElement.textContent = JSON.stringify(data, null, 2);
            responseElement.className = 'response ' + (isError ? 'error' : 'success');
        }

        // 1. 学生基本信息管理
        // 新增学生
        document.getElementById('createBasicForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const jsonData = formToJson(e.target);
                const response = await fetch(`${API_BASE_URL}/student/basic`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(jsonData)
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('basicResponse', result);
            } catch (error) {
                showResponse('basicResponse', error, true);
            }
        });

        // 查询学生
        document.getElementById('getBasicForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const studentId = e.target.querySelector('input[name="student_id"]').value;
                const response = await fetch(`${API_BASE_URL}/student/basic/${studentId}`);

                const result = await response.json();
                if (!response.ok) throw result;

                // 填充到更新表单
                const updateForm = document.getElementById('updateBasicForm');
                updateForm.querySelector('input[name="student_id"]').value = studentId;
                Object.keys(result).forEach(key => {
                    const input = updateForm.querySelector(`[name="${key}"]`);
                    if (input) input.value = result[key] || '';
                });

                showResponse('basicResponse', result);
            } catch (error) {
                showResponse('basicResponse', error, true);
            }
        });

        // 更新学生
        document.getElementById('updateBasicForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const studentId = e.target.querySelector('input[name="student_id"]').value;
                if (!studentId) throw { detail: '请先查询学生信息' };

                const jsonData = formToJson(e.target);
                const response = await fetch(`${API_BASE_URL}/student/basic/${studentId}`, {
                    method: 'PUT',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(jsonData)
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('basicResponse', result);
            } catch (error) {
                showResponse('basicResponse', error, true);
            }
        });

        // 删除学生
        document.getElementById('deleteBasicBtn').addEventListener('click', async () => {
            try {
                const studentId = document.getElementById('updateBasicForm').querySelector('input[name="student_id"]').value;
                if (!studentId) throw { detail: '请先查询学生信息' };

                if (!confirm(`确定要删除学生编号为 ${studentId} 的信息吗？`)) return;

                const response = await fetch(`${API_BASE_URL}/student/basic/${studentId}`, {
                    method: 'DELETE'
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('basicResponse', result);
            } catch (error) {
                showResponse('basicResponse', error, true);
            }
        });

        // 查询所有学生
        document.getElementById('getAllBasicForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const skip = e.target.querySelector('input[name="skip"]').value;
                const limit = e.target.querySelector('input[name="limit"]').value;
                const response = await fetch(`${API_BASE_URL}/student/basic?skip=${skip}&limit=${limit}`);

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('basicResponse', result);
            } catch (error) {
                showResponse('basicResponse', error, true);
            }
        });

        // 2. 学生考核成绩管理
        // 新增考核成绩
        document.getElementById('createScoreForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const jsonData = formToJson(e.target);
                const response = await fetch(`${API_BASE_URL}/student/score`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(jsonData)
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('scoreResponse', result);
            } catch (error) {
                showResponse('scoreResponse', error, true);
            }
        });

        // 查询学生成绩
        document.getElementById('getScoreForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const studentId = e.target.querySelector('input[name="student_id"]').value;
                const response = await fetch(`${API_BASE_URL}/student/score/${studentId}`);

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('scoreResponse', result);
            } catch (error) {
                showResponse('scoreResponse', error, true);
            }
        });

        // 查询所有成绩
        document.getElementById('getAllScoreForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const skip = e.target.querySelector('input[name="skip"]').value;
                const limit = e.target.querySelector('input[name="limit"]').value;
                const response = await fetch(`${API_BASE_URL}/student/score?skip=${skip}&limit=${limit}`);

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('scoreResponse', result);
            } catch (error) {
                showResponse('scoreResponse', error, true);
            }
        });

        // 3. 学生考勤记录管理
        // 新增考勤记录
        document.getElementById('createAttendanceForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const jsonData = formToJson(e.target);
                const response = await fetch(`${API_BASE_URL}/student/attendance`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(jsonData)
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('attendanceResponse', result);
            } catch (error) {
                showResponse('attendanceResponse', error, true);
            }
        });

        // 查询学生考勤
        document.getElementById('getAttendanceForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const studentId = e.target.querySelector('input[name="student_id"]').value;
                const response = await fetch(`${API_BASE_URL}/student/attendance/${studentId}`);

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('attendanceResponse', result);
            } catch (error) {
                showResponse('attendanceResponse', error, true);
            }
        });

        // 查询所有考勤
        document.getElementById('getAllAttendanceForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const skip = e.target.querySelector('input[name="skip"]').value;
                const limit = e.target.querySelector('input[name="limit"]').value;
                const response = await fetch(`${API_BASE_URL}/student/attendance?skip=${skip}&limit=${limit}`);

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('attendanceResponse', result);
            } catch (error) {
                showResponse('attendanceResponse', error, true);
            }
        });

        // 4. 学生就业信息管理
        // 新增就业信息
        document.getElementById('createEmploymentForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const jsonData = formToJson(e.target);
                const response = await fetch(`${API_BASE_URL}/student/employment`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(jsonData)
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('employmentResponse', result);
            } catch (error) {
                showResponse('employmentResponse', error, true);
            }
        });

        // 查询就业信息
        document.getElementById('getEmploymentForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const studentId = e.target.querySelector('input[name="student_id"]').value;
                const response = await fetch(`${API_BASE_URL}/student/employment/${studentId}`);

                const result = await response.json();
                if (!response.ok) throw result;

                // 填充到更新表单
                const updateForm = document.getElementById('updateEmploymentForm');
                updateForm.querySelector('input[name="student_id"]').value = studentId;
                Object.keys(result).forEach(key => {
                    const input = updateForm.querySelector(`[name="${key}"]`);
                    if (input) {
                        // 处理日期时间格式
                        let value = result[key];
                        if (value && (key === '就业开放时间' || key === 'OFFER下发时间')) {
                            // 转换为本地日期时间格式
                            value = value.replace(' ', 'T').replace('Z', '');
                        }
                        input.value = value || '';
                    }
                });

                showResponse('employmentResponse', result);
            } catch (error) {
                showResponse('employmentResponse', error, true);
            }
        });

        // 更新就业信息
        document.getElementById('updateEmploymentForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const studentId = e.target.querySelector('input[name="student_id"]').value;
                if (!studentId) throw { detail: '请先查询就业信息' };

                const jsonData = formToJson(e.target);
                const response = await fetch(`${API_BASE_URL}/student/employment/${studentId}`, {
                    method: 'PUT',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(jsonData)
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('employmentResponse', result);
            } catch (error) {
                showResponse('employmentResponse', error, true);
            }
        });

        // 删除就业信息
        document.getElementById('deleteEmploymentBtn').addEventListener('click', async () => {
            try {
                const studentId = document.getElementById('updateEmploymentForm').querySelector('input[name="student_id"]').value;
                if (!studentId) throw { detail: '请先查询就业信息' };

                if (!confirm(`确定要删除学生编号为 ${studentId} 的就业信息吗？`)) return;

                const response = await fetch(`${API_BASE_URL}/student/employment/${studentId}`, {
                    method: 'DELETE'
                });

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('employmentResponse', result);
            } catch (error) {
                showResponse('employmentResponse', error, true);
            }
        });

        // 查询所有就业信息
        document.getElementById('getAllEmploymentForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            try {
                const skip = e.target.querySelector('input[name="skip"]').value;
                const limit = e.target.querySelector('input[name="limit"]').value;
                const response = await fetch(`${API_BASE_URL}/student/employment?skip=${skip}&limit=${limit}`);

                const result = await response.json();
                if (!response.ok) throw result;
                showResponse('employmentResponse', result);
            } catch (error) {
                showResponse('employmentResponse', error, true);
            }
        });
    </script>
</body>
</html>